#!/sbin/openrc-run
supervisor=supervise-daemon

name="Caddy webserver"
command=/usr/sbin/caddy1
command_args="$CADDY_OPTS"
command_user=caddy:caddy
extra_commands="checkconfig"
extra_started_commands="reload"

depend() {
	need net localmount
	after firewall
}

checkconfig() {
	ebegin "Checking configuration for $RC_SVCNAME"
	su -s /bin/sh ${command_user%:*} -c "$command $command_args -validate"
	eend $?
}

reload() {
	checkconfig || return $?
	ebegin "Reloading $RC_SVCNAME"
	supervise-daemon $RC_SVCNAME --signal USR1
	eend $?
}

start_pre() {
	if [ "$RC_CMD" != "restart" ]; then
		checkconfig || return $?
	fi
}

stop_pre() {
	if [ "$RC_CMD" == "restart" ]; then
		checkconfig || return $?
	fi
}
